package com.wutianyi;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

import com.wutianyi.module.company.CompanyProto;
import com.wutianyi.module.company.CompanyProto.Company;

public class CompanyProtoMain
{
    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException
    {
        UUID uuid = UUID.randomUUID();
        String description = "This page describes exactly what Java code the protocol buffer compiler generates for any given protocol definition. You should read the language guide before reading this document.";
        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd : hh:mm:ss");
        String gmtCreate = dateformat.format(new Date());
        String gmtModified = dateformat.format(new Date());
        String name = "This page describes exactly what Java code the protocol buffer compiler generates for any given protocol definition. You should read the language guide before reading this document.";
        String nameEn = "English";

        Company company = CompanyProto.Company.newBuilder().setCompanyId(uuid.toString()).setDescription(description)
                .setExCategoryId(1).setGmtCreate(gmtCreate).setGmtModified(gmtModified).setName(name).setNameEn(nameEn)
                .build();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        long start = System.currentTimeMillis();
        company.writeTo(baos);
        System.out.println("use times: " + (System.currentTimeMillis() - start));
        System.out.println(baos.toByteArray().length);
        
        start = System.currentTimeMillis();
        Company.parseFrom(baos.toByteArray());
        System.out.println("use times: " + (System.currentTimeMillis() - start));
    }
}
